using System.Linq;
using FutureApp.EntityFramework;
using FutureApp.MultiTenancy;

namespace FutureApp.Migrations.SeedData
{
    public class DefaultTenantCreator
    {
        private readonly FutureAppDbContext _context;

        public DefaultTenantCreator(FutureAppDbContext context)
        {
            this._context = context;
        }

        public void Create()
        {
            this.CreateUserAndRoles();
        }

        private void CreateUserAndRoles()
        {
            //Default tenant

            var defaultTenant = this._context.Tenants.FirstOrDefault(t => t.TenancyName == Tenant.DefaultTenantName);
            if (defaultTenant == null)
            {
                this._context.Tenants.Add(new Tenant {TenancyName = Tenant.DefaultTenantName, Name = Tenant.DefaultTenantName});
                this._context.SaveChanges();
            }
        }
    }
}
